package testDay;

public class day3_3 {
    //滑动窗口：1.计数，2.比较数，3.左右指针，
    public int numSubarrayProductLessThanK(int[] nums, int k) {
        int count = 0;//计数，返回值
        int product = 1;//乘积
        int left = 0;//左指针
        for (int right = 0;right<nums.length;right++){
            product *=nums[right];
            while (left<=right&&product>=k){
                product /=nums[left];
                left++;
            }
            count +=right-left+1;
        }
        return count;
/*        int count = 0;
        for (int left = 0;left<nums.length;left++){
            int temp = nums[left];
            for (int right = left;right<nums.length;right++){
                temp *=nums[right];
                if (temp>=k){
                    break;
                }
                count++;
            }
        }
        return count;*/
    }
}
